package com.demo.rbactest.Config;

import com.demo.rbactest.handle.TokenHandel;
import com.demo.rbactest.handle.CorsHandel;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器配置
 */

@Configuration
public class WebConfig implements WebMvcConfigurer {

    final
    CorsHandel corsHandel; // 跨域处理

    final
    TokenHandel tokenHandel; // token处理

    public WebConfig(TokenHandel loginHandel, CorsHandel norsInterceptor) {
        this.tokenHandel = loginHandel;
        this.corsHandel = norsInterceptor;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
//        放行跨域
        registry.addInterceptor(corsHandel).addPathPatterns("/**");
        //验证token
        registry.addInterceptor(tokenHandel).addPathPatterns("/**");
    }

}
